package com.example.demo.util;

import java.text.SimpleDateFormat;
import java.util.*;

public class Test {
    public static void main(String[] args) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        TreeMap<String,Team> map = new TreeMap<>();
        for (int i = 0; i <7 ; i++) {
            Date date1 = getTheDayBefore(i);
            String key = simpleDateFormat.format(date1);
            map.put(key,getTeam(date1));
        }
        map.forEach((k,v)-> System.out.println(k+"-"+v));



    }

    private static Date getTheDayBefore(int dayVal) {
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(new Date());
        calendar2.add(Calendar.DATE, -dayVal);
        return calendar2.getTime();
    }

    public static Team getTeam(Date date){
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(date);
        calendar2.set(Calendar.HOUR_OF_DAY, 0);
        calendar2.set(Calendar.MINUTE, 0);
        calendar2.set(Calendar.SECOND, 0);
        Date startDate = calendar2.getTime();

        Calendar calendar3 = Calendar.getInstance();
        calendar3.setTime(date);
        calendar3.set(Calendar.HOUR_OF_DAY, 23);
        calendar3.set(Calendar.MINUTE, 59);
        calendar3.set(Calendar.SECOND, 59);
        Date endDate = calendar3.getTime();
        return  new Team(startDate,endDate);
    }
    public static class  Team {
        private  Date startDate;
        private  Date endDate;
        public Team(Date startDate, Date endDate) {
            this.startDate = startDate;
            this.endDate = endDate;
        }
        public Date getStartDate() {
            return startDate;
        }
        public Date getEndDate() {
            return endDate;
        }

        @Override
        public String toString() {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            return "Team{" +
                    "startDate=" + simpleDateFormat.format(startDate) +
                    ", endDate=" + simpleDateFormat.format(endDate) +
                    '}';
        }
    }
}
